<?php
/**
 * 后台主页控制器
 * User: xuyiping(xuyiping@liangzihuzhu.com)
 * Date: 2017/12/1
 * Time: 14:44
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Symfony\Component\HttpFoundation\Request;
use App\Model\Record\RecordModel;
class RecordController extends Controller
{

    public function index($p,$user,$type){

    }
    public function Record($iRecordType=1,$iRcordSql="",$iRecordCode="",$sRecordRemark=""){
        $userId = session('ADMIN_USER_ID'.session()->getId());
        $model = new RecordModel();
        return $model->addRecord([
            "iRecordType"   => $iRecordType,
            "iRcordSql"     => $iRcordSql,
            "iRecordCode"   => $iRecordCode,
            "sRecordRemark" => $sRecordRemark,
            "dtCommitTime"  => date("Y-m-d H:i:s"),
            "sModifyUser"   => $userId,
            //"sModifyUser"   => "system",
            "sIp"           => $_SERVER['REMOTE_ADDR']
        ]);
    }

    public function lookindex(){
        return view('Admin/Record/index', array());
    }
    public function searchRecord(Request $request){
       $where = [];
        //查询条件
        if ($request->input('iSeqId')) {
            $where['iSeqId'] = $request->input('iSeqId');
        }
        if ($request->input('iRecordType')) {
            $where['iRecordType'] = $request->input('iRecordType');
        }
        if ($request->input('sModifyUser')) {
            $where['sModifyUser'] = $request->input('sModifyUser');
        }
        $groups = RecordModel::where($where)
            ->orderBy($request->input('sort'), $request->input('order'))
            ->paginate($request->input('limit'))
            ->toArray();
        //返回数组
        $res_data = array(
            'total' => $groups['total'],
            'rows' => array()
        );

        foreach ( $groups['data'] as &$row ) {

            // = '<a href="javascript: void(0);" onclick="Role.del(' . $row['roleID'] . ');">删除</a>&nbsp&nbsp';
           // $operation .= '<a href="javascript: void(0);" onclick="Role.edit(' . $row['roleID'] . ');">修改</a>&nbsp&nbsp';
           // $operation .= '<a href="javascript: void(0);" onclick="Role.permission(' . $row['roleID'] . ');">权限</a>&nbsp&nbsp';
            $row['operation']='';
            $res_data['rows'][] = $row;
        }
        record('sql','查看日志');//记录操作
        return response()->json($res_data);
    }
}